package com.longxi.tianjintianbao.ui.adapter.multitype.houseinspection;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.AdapterListener;
import com.longxi.tianjintianbao.model.houseinspection.YanFang;
import com.longxi.tianjintianbao.model.task.Task;
import com.longxi.tianjintianbao.utils.MyUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class YanFangBinder extends ItemViewBinder<YanFang, YanFangBinder.ViewHolder> {

    private AdapterListener listener;
    private String type;
    private String[] state = {"未验房","验房中","已验房","未恢复","已恢复"};
    private int[] textColor = {R.color.color_onpress_red,R.color.color_onpress_red,R.color.color_text3,R.color.color_onpress_red,R.color.color_text3};

    public YanFangBinder(AdapterListener listener, String type) {
        this.listener = listener;
        this.type = type;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_yanfang, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull YanFang yanFang) {
        holder.mTvTime.setText(yanFang.getBilldate());
        holder.mTvStatus.setText(yanFang.getBillstate());
        holder.mTvStatus.setTextColor(MyUtils.getResource().getColor(R.color.color_onpress_red));
        holder.mTvYanFangLeft.setText("单据编号: "+ yanFang.getBillcode() + "\n客户姓名: " + yanFang.getCustname());
        holder.mTvYanFangRight.setText("验房房号: "+ yanFang.getHousecode() + "\n入住日期: " + yanFang.getCheckindate());
        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onClick(holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout mLlBtn;
        TextView mTvTime;
        TextView mTvStatus;
        TextView mTvYanFangLeft;
        TextView mTvYanFangRight;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvTime = itemView.findViewById(R.id.tvTime);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
            mTvYanFangLeft = itemView.findViewById(R.id.tvYanFangLeft);
            mTvYanFangRight = itemView.findViewById(R.id.tvYanFangRight);
            switch (type) {
                case "0":
                case "1":
                    mTvYanFangLeft.setHint("单据编号: 无\n客户姓名: 无");
                    mTvYanFangRight.setHint("退房房号: 无\n入住日期: 无");
                    break;
                case "2":
                    mTvYanFangLeft.setHint("单据编号: 无\n客户姓名: 无");
                    mTvYanFangRight.setHint("退房房号: 无\n退住日期: 无");
                    break;
            }
        }
    }
}
